import Mock from 'mockjs'

const data = []
for (let i = 0; i < 10; i++) {
  data.push(
    Mock.mock({
      // id: '@id',
      // avatar: '@image("100x100")',
      // title: '@ctitle(3,10)',
      // content: '@ctitle(10,40)',
      // createTime: '@datetime()',
      // status: '@integer(0,1)',
      // type: '@integer(1,3)'
      id: '@guid',
      name: '@cname',
      place: '@county(true)'
    })
  )
}

const rules = [
  {
    url: '/list',
    method: 'get',
    timeout: 100,
    response: () => {
      return {
        code: 10000,
        message: '模拟数据成功',
        data
      }
    }
  },
  {
    url: '/patient/message/sys/del',
    method: 'delete',
    response: ({ query }) => {
      const index = data.findIndex((item) => item.id === query.id)
      data.splice(index, 1)
      return { code: 1000, success: true }
    }
  },
  {
    url: '/patient/message/sys/edit',
    method: 'post',
    Response: (config) => {
      // const index = data.findIndex((item) => item.id === query.id)

      const body = config.body
      const index = data.findIndex((item) => {
        return item.id === body.id
      })
      data.splice(
        index,
        1,
        Mock.mock({
          id: body.id,
          name: body.name,
          place: body.place
        })
      )
      return { code: 1000, message: '修改成功', data }
    }
  }
]

export default rules
